<template>
	<view class="dwu-picker">
		<view class="picker" @click="chooseLocation">
			<u-input v-model="selectVal" inputAlign="right" border="none" :readonly="true" disabledColor="transparent" :disabled="disabled" :placeholder="placeholder"></u-input>
			<view class="arrow-down">
				<image src="@/static/news/arrow_right.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "dwu-chooseLocation",
		props: {
			placeholder: {
				type: String,
				default: '请选择'
			},
			defaultVal: {
				type: String,
				default: ''
			},
			disabled: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				selectVal: ''
			};
		},
		watch: {
			defaultVal(val) {
				this.selectVal = val
			}
		},
		methods: {
			chooseLocation() {
				if (this.disabled) return
				uni.chooseLocation({
					success: (res) => {
						this.amap.getAddressByLatLng(res.latitude, res.longitude).then(ress => {
							let addressComponent = ress.addressComponent
							let aois = ress.aois
							this.selectVal = addressComponent.province + addressComponent.city + addressComponent.district
							this.$emit('onconfirm', ress)
						})
					},
					fail: (err) => {
						console.log(err);
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.dwu-picker {
		.picker {
			display: flex;
			align-items: center;

			.arrow-down {
				display: flex;
				align-items: center;

				image {
					width: 10rpx;
					height: 18rpx;
				}
			}
		}
	}
</style>